using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XRPGLibrary.TileEngine
{
    public class Tileset
    {
        private Rectangle[] sourceRectangles;

        public Texture2D Texture { get; set; }
        public int TileWidth { get; set; }
        public int TileHeight { get; set; }
        public int TilesWide { get; set; }
        public int TilesHigh { get; set; }

        public Rectangle[] SourceRectangles
        {
            get { return (Rectangle[]) sourceRectangles.Clone(); }
        }

        public Tileset(Texture2D image, int tilesWide, int tilesHigh, int tileWidth, int tileHeight)
        {
            Texture = image;
            TileWidth = tileWidth;
            TileHeight = tileHeight;
            TilesWide = tilesWide;
            TilesHigh = tilesHigh;

            int tiles = TilesWide*TilesHigh;

            sourceRectangles = new Rectangle[tiles];
            int tile = 0;
            for (int y = 0; y < TilesHigh; y++)
            {
                for (int x = 0; x < TilesWide; x++)
                {
                    sourceRectangles[tile] = new Rectangle(
                        x * TileWidth,
                        y * TileHeight,
                        TileWidth,
                        TileHeight);
                    tile++;
                }
            }

        }
    }
}